// 顶部悬浮
// 

var topFloat = document.querySelector(".xuanfu")
window.onscroll = function(){
    // 获取滚动过的距离
    var t = document.documentElement.scrollTop || document.body.scrollTop;
    // console.log(t);
    // 如果滚动了30px的时候就应该显示top了
    if(t >= 30){
        // 设置topFloat的高度为30
        topFloat.style.transition = 'all 1s'
        // topFloat.style.height = '30px' 
        topFloat.style.display = 'block'
        topFloat.style.backgroundColor = '#fff'
    }
    else {
        // console.log(t);
        if(t === 0){
            topFloat.style.display = 'none'
        }
        topFloat.style.transition = 'none'
    }
}




$.ajax({
    url: "https://list.mogu.com/search",
    method: "get",
    dataType: "jsonp",
    data: {
      callback: "jQuery21106216481125759377_1635845448722",
      _version: 8193,
      ratio: "3:4",
      cKey: 15,
      page: 1,
      sort: "pop",
      ad: 0,
      action: "boyfriend",
      acm: "3.mce.1_10_1ko5c.132244.0.rQ9uSsNB6z4ey.pos_879-m_482180-sd_119",
      ptp: "31.v5mL0b._head.0.YZ9U1BZE",
      _: 1635845448723,
    },
    success: (res) => {
      // console.log(res);
      var data = res.result.wall.docs;
    //   console.log(data);
      var str = "";
      data.forEach((item) => {
        str += `
          <li>
              <img src="${item.img}">
              <p>${item.title}</p>
              <span class="price" style="color:red">￥${item.price}</span>
              <a href='detail.html?id=${item.tradeItemId}'>查看详情</a>
              <span class="sale"   style="color:orangered">销量${item.sale}</span>
          </li>
          `;
      });
      $(".data ul").html(str);
    },
  });
dl()
function dl(){
var tel = localStorage.getItem('tel')
var denglu = $('.header .center .left ul .denglu')
var zhuce = $('.header .center .left ul .zhuce')
// var tel = localStorage. getItem('tel')
// if(!tel){
//   layer.msg('请先登录',{
//     icon:2,
//     time:1000
//   },()=>{
//     localStorage.setItem('url',location.href)
//     location.href = './login.html'
//   })
// }
var str1 = ''
var str2 = ''
if(!tel){
  str1 += `
  <a href="./regeister.html">免费注册</a>
  `
  str2+=`
  <a href="./login.html">登录</a>
  `
  denglu.html(str2)
  zhuce.html(str1)
}else{
  str1+=`
  <span style="color:yellow">
  欢迎用户${tel}回来 
  </span>
  `
  str2+=`
  <a onclick='fn()'>退出</a>
  `
  denglu.html(str1)
  zhuce.html(str2)
}
}
function fn(){
  layer.confirm('您确定要退出吗？',{
    btn:['确定','取消'] 
},()=>{
    layer.msg('退出成功，请重新登录',{
      icon:1,
      time:1500
    })
})
  localStorage.removeItem('tel')
  setTimeout(function(){
    var tel = localStorage. getItem('tel')
  if(!tel){
    layer.msg('请先登录',{
      icon:2,
      time:1000
    },()=>{
      localStorage.setItem('url',location.href)
      location.href = './login.html'
    })
  }
  },3000)
  dl()
}